#!/bin/sh

BASE_DIR=$(cd "$(dirname "$0")"; pwd)/
cd $BASE_DIR

# 自动从*.properties中读取配置,不需要调整shell文件了
app_conf_dir=conf/

app_name=`cat $app_conf_dir/*.properties |grep "^spring.application.name" | tail -n 1 | cut -d "=" -f2- | awk '{print $1}'`

app_jar=$(ls *.jar|tail -n 1)


PID=`/bin/ps -ef | grep java | grep $app_jar | grep -v grep |awk '{print $2}'`

if [ -n "$PID" ]; then
    echo "进程$app_jar尝试关闭，进程号: $PID ..."
        kill -15 $PID
        sleep 3

        PID=`/bin/ps -ef | grep java | grep $app_jar | grep -v grep |awk '{print $2}'`
        if [ -n "$PID" ]; then
                kill -9 $PID
            echo "进程$app_jar强制关闭!"
        else
            echo "进程$app_jar关闭成功!"
        fi
    exit
else
    echo "进程$app_jar不存在!"
    exit
fi
